package com.gxuwz.eschool;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.gxuwz.eschool.bean.Menu;
import com.gxuwz.eschool.fragment.CardFragment;
import com.gxuwz.eschool.fragment.HomeFragment;
import com.gxuwz.eschool.fragment.MessageFragment;
import com.gxuwz.eschool.fragment.PersonFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TextView tv_home;
    private TextView tv_card;
    private TextView tv_message;
    private TextView tv_person;
    private HomeFragment homeFragment;
    private CardFragment cardFragment;
    private MessageFragment messageFragment;
    private PersonFragment personFragment;
    private FragmentTransaction fragmentTransaction;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        tv_home= findViewById(R.id.tv_home);
        tv_card= findViewById(R.id.tv_card);
        tv_message=findViewById(R.id.tv_message);
        tv_person =findViewById(R.id.tv_person);
        tv_home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setFragment(homeFragment);
            }
        });
        tv_card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setFragment(cardFragment);
            }
        });
        tv_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setFragment(messageFragment);
            }
        });
        tv_person.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {



                setFragment(personFragment);

            }


        });
        //创建Fragment
        homeFragment=new HomeFragment();
        cardFragment=new CardFragment();
        messageFragment=new MessageFragment();
        personFragment=new PersonFragment();
        setFragment(homeFragment);




    }
    private void setFragment(Fragment fragment){
        fragmentTransaction =getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.layout_container,fragment);
        fragmentTransaction.commit();
    }












}

//
//    private ListView listView;
//    private List<Menu> dataes;
//class MyBaseAdapter extends BaseAdapter {
//    @Override
//    public int getCount() {
//        return dataes.size();
//    }
//    @Override
//    public Menu getItem(int position) {
//        return dataes.get(position);
//    }
//    @Override
//    public long getItemId(int position) {
//        return position;
//    }
//    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//        View view = View.inflate(MainActivity.this, R.layout.list_menu,null);
//        TextView name = view.findViewById(R.id.person_menu_name);
//
//        ImageView pic = view.findViewById(R.id.person_menu_img);
//
//        Menu menu = getItem(position);
//        name.setText(menu.getMenuName());
//
//        pic.setBackgroundResource(menu.getPic());
//        return view ;

//    }
//}


//    private void initData(){
//        this.dataes = new ArrayList<>();
//        Menu apple1 = new Menu("交易记录",R.drawable.img);
//        Menu apple2 = new Menu("交易记录",R.drawable.img);
//        Menu apple3 = new Menu("交易记录",R.drawable.img);
//        Menu apple4 = new Menu("交易记录",R.drawable.img);
//        Menu apple5 = new Menu("交易记录",R.drawable.img);
//
//        this.dataes.add(apple1);
//        this.dataes.add(apple2);
//        this.dataes.add(apple3);
//        this.dataes.add(apple4);
//        this.dataes.add(apple5);
//    }

//
//     listView = findViewById(R.id.person_list_menu);
//             this.initData();
//             MyBaseAdapter myBaseAdapter = new MyBaseAdapter();
//             listView.setAdapter(myBaseAdapter);